﻿-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [_Old_Temp_PivotModel]
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

	DECLARE @cols AS NVARCHAR(MAX),
		@query  AS NVARCHAR(MAX)

	select @cols = STUFF((SELECT  ',' + QUOTENAME(AttributeID) 
						from Attributes
						group by AttributeID
						order by AttributeID
				FOR XML PATH(''), TYPE
				).value('.', 'NVARCHAR(MAX)') 
			,1,1,'')




	set @query = 'SELECT * 
					from Attributes
				pivot 
				(
					max(AttributeValueStr)
					for AttributeID in (' + @cols + ')
				) p '


	execute(@query)
END
